import platform

from fastapi import APIRouter

from src.services.system.metric_service import MetricsService
from src.types.metric import Metric
from src.utils.rs import Rs

router = APIRouter()


@router.get("/", response_model=Rs[Metric], summary="首页")
async def root():
    """首页"""
    pip_list_output = await MetricsService().pip_list()
    python_version_output = await MetricsService().python_version()
    return Rs().ok(data=Metric(
        docs="/docs",
        libraries=pip_list_output.split("\n"),
        os=platform.platform(),
        python=python_version_output
    ))


@router.get("/health", response_model=Rs, summary="健康检查")
async def health_check():
    """
    健康检查
    """
    return Rs().ok()
